using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LinkNote.Core;
using LinkNote.Model;
using MonoTouch.SQLite;

namespace LinkNote
{
    public class DBHelper
    {
        private static SQLiteConnection dbconn;

        public static SQLiteConnection sqlitedb
        {
            get
            {
                if(dbconn==null)
                    InitDB();
                return dbconn;
            }
        }

        private static void InitDB()
        {
            string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "linknote.sqlite");

            //bool exists = File.Exists(dbPath);
            //if (!exists)
            //    SqliteConnection.CreateFile(dbPath);
            //var connection = new SqliteConnection("Data Source=" + dbPath);
            //connection.Open();

            var sqlitedb = new SQLiteConnection(dbPath);
            dbconn = sqlitedb;
            sqlitedb.CreateTable<User>();
            sqlitedb.CreateTable<NoteClass>();
            sqlitedb.CreateTable<LinkNoteFile>();
            sqlitedb.CreateTable<AttachmentBlock>();
            sqlitedb.CreateTable<MainBody>();
            //sqlitedb.CreateTable<AudioBlock>();
            //sqlitedb.CreateTable<VideoBlock>();
            //sqlitedb.CreateTable<PictureBlock>();
            sqlitedb.CreateTable<NoteLabel>();
            //sqlitedb.CreateTable<NoteLabelMap>();
        }
    }
}